/*
 * Copyright (c) 2020
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-06     chao         the first version
 */

#ifndef __MY_BUTTON_H__
#define __MY_BUTTON_H__

#include <rtthread.h>

#define MY_BUTTON_DOWN_MS           50
#ifndef MY_BUTTON_HOLD_TRI_MS
#define MY_BUTTON_HOLD_TRI_MS       800
#endif
#ifndef MY_BUTTON_HOLD_CYC_MS
#define MY_BUTTON_HOLD_CYC_MS       200
#endif
#define MY_BUTTON_SCAN_SPACE_MS     20
#ifndef MY_BUTTON_LIST_MAX
#define MY_BUTTON_LIST_MAX          10
#endif

typedef void (*my_button_callback)(void*);

enum my_button_event
{
    BUTTON_EVENT_CLICK_DOWN,
    BUTTON_EVENT_CLICK_UP,
    BUTTON_EVENT_HOLD_TRI,
    BUTTON_EVENT_HOLD_CYC,
    BUTTON_EVENT_HOLD_UP,
    BUTTON_EVENT_NONE
};

struct my_button
{
    rt_uint8_t  press_logic_level;
    rt_uint16_t cnt;
    rt_uint16_t hold_tri_time;
    rt_uint16_t hold_cyc_period;
    rt_uint16_t pin;

    enum my_button_event event;

    my_button_callback cb;
};

int my_button_register(struct my_button *button);
int my_button_start(void);

#endif /* __MY_BUTTON_H__ */


